package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.KUserMapper;
import com.example.pojo.KUser;
import com.example.service.IKUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author panghu
 * @version 1.0.0
 * @createTime 2023年09月09日 18:50:00
 * @Description
 */
@Service
@Slf4j
public class KUserServiceImpl extends ServiceImpl<KUserMapper, KUser> implements IKUserService {

    /**
     * 添加或修改用户
     */
    @Override
    public KUser saveOrUpdateUser(KUser kUser){
        boolean flag = this.saveOrUpdate(kUser);
        return flag ? kUser : null;
    }

    /**
     * 删除用户
     */
    @Override
    public Integer deleleUserByUserId(Long userId){
        boolean b = this.removeById(userId);
        return b ? 1 : 0;
    }



    /**
     * 分页查询用户信息
     */
    @Override
    public IPage<KUser> selelctUserPages(Integer pageNo, Integer pageSize){
        Page<KUser> page = new Page<>(pageNo,pageSize);
        LambdaQueryWrapper<KUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return this.page(page,lambdaQueryWrapper);
    }


    /**
     * 查询所有的用户信息
     */
    @Override
    public List<KUser> selelctUserList(){
        LambdaQueryWrapper<KUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return this.list(lambdaQueryWrapper);
    }


    /**
     * 根据用户id查询用户信息
     */
    @Override
    public KUser selectUserByUserId(Long userId){
        return this.getById(userId);
    }

}
